package cn.tonyqiu.wonuly.client.gui;

import cn.tonyqiu.wonuly.client.i18n.WonulyConstants;
import cn.tonyqiu.wonuly.client.i18n.WonulyMessages;
import cn.tonyqiu.wonuly.client.images.WonulyImageBundle;
import cn.tonyqiu.wonuly.client.rpc.WonulyServiceAsync;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Wonuly implements EntryPoint {

	/**
	 * this static constants,images,messages used throughout the Wonuly
	 */
	public static final WonulyConstants constants = GWT
			.create(WonulyConstants.class);

	public static final WonulyImageBundle images = GWT
			.create(WonulyImageBundle.class);

	public static final WonulyMessages messages = GWT
			.create(WonulyMessages.class);
	
	private static Wonuly singleton;

	private Shortcuts shortcuts = new Shortcuts();
	private TopPanel topPanel = new TopPanel();
	private DockPanel outer = new DockPanel();
	
	WonulyServiceAsync wonulyAsync;
	BillContentList contentList = new BillContentList();
	AddPanel addPanel;

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {

		singleton = this;
		
		topPanel.setWidth("100%");

		
		outer.add(topPanel, DockPanel.NORTH);
		outer.add(shortcuts, DockPanel.WEST);
		
		outer.setWidth("100%");

		showContentList();
		
		RootPanel.get().add(outer);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.google.gwt.user.client.WindowResizeListener#onWindowResized(int,
	 * int)
	 */

	public void onWindowResized(int width, int height) {
		// TODO Auto-generated method stub

	}
	
	public static Wonuly get() {
		return singleton;
	}
	
	public void showAddPanel() {
		if(addPanel == null) addPanel = new AddPanel();
		if(contentList != null) outer.remove(contentList);
		outer.add(addPanel,DockPanel.EAST);
		outer.setSpacing(4);
		outer.setCellWidth(addPanel, "100%");
	}
	
	public void showContentList() {
		if(contentList == null) contentList = new BillContentList();
		if(addPanel != null) outer.remove(addPanel);
		outer.add(contentList, DockPanel.EAST);

		outer.setSpacing(4);
		outer.setCellWidth(contentList, "100%");
	}
}
